@isTest
private class AccessoryWarrantyControllerTest {
    static testMethod void testMethod1() {
        
         Id ldcProfile = [Select Id From Profile Where Name like '%工程师%' limit  1  ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Username = 'Matldc1@test.com.maike',
                         FederationIdentifier ='123451', 
                         Province__c  = '四川省',
                         ManagerId=UserInfo.getUserId(), 
                         ResponseCode__c = 'TTTT' );
         insert u1; 

        Account acc=new Account();
    	acc.Name='Test1229J';
    	insert acc;
    	

        Product__c p = TestUtils.createProduct();
        p.Brand__c = '迈克';
        p.Company__c = '四川省迈克实业有限公司';
        p.Category3__c = '仪器';
        p.Category0__c = '仪器';

        p.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p.NCCode__c = '1001110000';
        insert p;

        Equipment__c e1 = new Equipment__c();
        e1.Account__c = acc.Id;
        e1.IMEINumber__c = '11';
        e1.Product__c = p.Id;
        e1.EndDate__c = System.today();
        insert e1;
        Case cas=new Case();
        cas.AccountId=acc.Id;
        cas.Engineer__c = u1.Id ;
        cas.ServiceManufacture__c = e1.Id;
        insert cas;
    	
    	WorkOrder__c wo=new WorkOrder__c();
    	wo.Case__c=cas.Id;
    	wo.Account__c=acc.Id;
    	wo.Status__c='处理中';

        wo.Technician__c  = u1.Id ;
        wo.ServiceManufacture__c = e1.Id; 
        wo.InventoryOrganization__c = 'MKSY';
        wo.PartsInvoicingCustomers__c = acc.Id;
    	insert wo;

        Product__c p1 = TestUtils.createProduct();
        p1.Brand__c = '迈克';
        p1.Company__c = '四川省迈克实业有限公司';
        p1.Category3__c = '配件';
        p1.Category0__c = '配件';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p1.NCCode__c = '1101110000';
        p1.Category1__c = '配件';
        p1.ProductName__c = '测试配件';
        insert p1; 

        Price__c pr1 = new Price__c(
            Product__c = p1.Id,
            Company__c = '四川省迈克实业有限公司',
            CompanyBottomPrice__c = 1.0,
            HospitalBottomPrice__c = 1.0,
            InvoiceDealerPrice__c = 1.0,
            AreaDealerPrice__c = 1.0,
            MarketPrice__c = 1.0,
            HospitalManagerPrice__c= 1.0,
            InstCost__c = 0.5
            
        );

        insert pr1;

      

            PartsLendingApplication__c pla = new PartsLendingApplication__c();
            pla.IsSycToNc__c = true;
            pla.InventoryOrganization__c = 'MKSY';
            pla.OwnerId = u1.Id ;
            insert pla;

            PartsLendingDetails__c pld = new PartsLendingDetails__c();
            pld.Product__c = p1.Id;
            pld.No__c =5;
            pld.A_InvoiceNo__c = 1;
            pld.A_WarrantyNo__c =1;
            pld.B_No__c = 5;
            pld.PartsLendingApplication__c = pla.Id;
            insert pld;

            WorkOrderProduct__c wop = new WorkOrderProduct__c();

            wop.WorkOrder__c  = wo.Id;
            wop.Product__c = p1.Id;
            wop.PartsLendingDetails__c = pld.Id;
            wop.Quantity__c = 2;
            wop.WarrantyNo__c = 1;
            wop.InvoiceNo__c = 1;
            insert wop;


            

                PageReference page2 = new PageReference('/apex/AccessoryWarranty?id='+wo.Id);
                System.Test.setCurrentPage(page2);

                AccessoryWarrantyController pra = new AccessoryWarrantyController();
                pra.init();
                Map<String,Object> saveMap =new Map<String,Object>();
                Map<String,String> baseMap =new Map<String,String>();

                baseMap.put('DocumentTypes__c','库存其他出库单');
                saveMap.put('base', baseMap);

                saveMap.put('datas', ((Map<String,Object>)JSON.deserializeUntyped(EncodingUtil.urlDecode(pra.dataJson, 'UTF-8'))).get('search') );
                System.debug('PartsInvoiceApplicationControllerTest==>'+saveMap);
                pra.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');
                pra.save();
                System.debug('PartsInvoiceApplicationControllerTest==>'+pra.msg);
                AccessoryWarranty__c pa = [select Id from AccessoryWarranty__c limit 1 ];
                PageReference page1 = new PageReference('/apex/AccessoryWarranty?id='+pa.Id);
                System.Test.setCurrentPage(page1);

                AccessoryWarrantyController pra1 = new AccessoryWarrantyController();
                pra1.init();

                pra1.pdfRerender();

            
            




        
    }
}